package cn.edu.nju.software.zp13.core2.nodeDescriptorFactory;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import cn.edu.nju.software.zp13.core2.annotation.Attribute;
import cn.edu.nju.software.zp13.core2.annotationParser.AnnotationParser;
import cn.edu.nju.software.zp13.core2.nodeDescriptor.NodeDescriptor;
import cn.edu.nju.software.zp13.core2.nodeDescriptor.NodeType;
import cn.edu.nju.software.zp13.core2.xmlNodeEntity.XmlNodeEntity;

public class AttributeNodeDescriptorFactory implements NodeDescriptorFactory{
	private Attribute attributeAnnotation;
	private String attriName;
	
	public AttributeNodeDescriptorFactory(Attribute attributeAnnotation) {
		super();
		this.attributeAnnotation = attributeAnnotation;
	}

	@Override
	public NodeDescriptor generateNodeDescriptor(Field f, Method[] methods, XmlNodeEntity entity) {
		attriName=AnnotationParser.getAttributeName(f, attributeAnnotation);
		NodeDescriptor nd=new NodeDescriptor();
		nd.setType(NodeType.AttributeNode);
		nd.setNodeName(attriName);
		for(Method m:methods){
			Attribute methodAttriAnno=m.getAnnotation(Attribute.class);
			if(methodAttriAnno!=null&&attriName.equals(methodAttriAnno.name())){
				//nd.setMethod(m);
			}
		}
		return nd;
	}
}
